#include "shdevice.h"
#include "sh/shnet.h"
#include "qtquick2applicationviewer.h"
#include <QQuickItem>
#include <QDebug>

ShDevice::ShDevice(QObject *parent) :
    QObject(parent)
{
    m_sh = new ShNet(this);
    if (!m_sh->join(QHostAddress("192.168.7.7"),
                    QHostAddress("239.1.1.1"), 45454, "projector_screen_ui")) {
        qWarning() << "sh join failed :(";
        return;
    }

    m_qml = new QtQuick2ApplicationViewer;
    m_qml->setMainQmlFile(QStringLiteral("qml/ui/main.qml"));
    m_qml->showExpanded();

    connect(m_qml->rootObject(), SIGNAL(upPressed()), this, SLOT(onUpPressed()));
    connect(m_qml->rootObject(), SIGNAL(downPressed()), this, SLOT(onDownPressed()));
}

void ShDevice::onUpPressed()
{
    m_sh->setProperty(Url("projector_screen/state=up"));
}

void ShDevice::onDownPressed()
{
    m_sh->setProperty(Url("projector_screen/state=down"));
}
